<?php
class Admin_ItemController extends Zend_Controller_Action
{
	private $t;
	private $hash;

	public function preDispatch()
	{
		$this->t = Zend_Registry::get('Zend_Translate');
		$this->view->t = $this->t;
	}

	public function saveAction()
	{
		$type = $this->_request->getParam('type');
		$items = new Types();
		$itemFields = new ItemFields();

		$item = $items->fetchRow("`name` = '{$type}'");
		$fields = $itemFields->fetchAll("`itemTypeId` = '{$item->id}'");

		if($item != NULL) {
			$form = new Zend_Form();
			$form->setName('item' . $type);

			foreach($fields as $field) {
				$element = $this->_helper->FormBuilder($field->field, $field->name);
				if(is_object($element)) {
					$form->addElement($element);
				}
			}

			$this->view->form = $form;
		}
	}
}